package query

import (
	
)

const All = "$__all"

// Option represents an option that can be used to configure a query.
type Option func(constant *Query)

// SortOrder represents the ordering method applied to values.
type SortOrder int

const (
	// None will preserve the results ordering as returned by the query.
	None SortOrder = 0

	// AlphabeticalAsc will sort the results by ascending alphabetical order.
	AlphabeticalAsc SortOrder = 1

	// AlphabeticalDesc will sort the results by descending alphabetical order.
	AlphabeticalDesc SortOrder = 2

	// NumericalAsc will sort the results by ascending numerical order.
	NumericalAsc SortOrder = 3

	// NumericalDesc will sort the results by descending numerical order.
	NumericalDesc SortOrder = 4

	// AlphabeticalNoCaseAsc will sort the results by ascending alphabetical order, case-insensitive.
	AlphabeticalNoCaseAsc SortOrder = 5

	// AlphabeticalNoCaseDesc will sort the results by descending alphabetical order, case-insensitive.
	AlphabeticalNoCaseDesc SortOrder = 6
)

// RefreshInterval represents the interval at which the results of a query will
// be refreshed.
type RefreshInterval int

const (
	// Never will prevent the results from being refreshed.
	Never = 0

	// DashboardLoad will refresh the results every time the dashboard is loaded.
	DashboardLoad = 1

	// TimeChange will refresh the results every time the time interval changes.
	TimeChange = 2
)

// Query represents a "query" templated variable.
type Query struct {
	Builder sdk.TemplateVar
}

// New creates a new "query" templated variable.
func ( string,  ...Option) *Query {
	 := &Query{Builder: sdk.TemplateVar{
		Name:    ,
		Label:   ,
		Type:    "query",
		Options: []sdk.Option{},
	}}

	for ,  := range append([]Option{Refresh(DashboardLoad)}, ...) {
		()
	}

	return 
}

// DataSource sets the data source to be used by the query.
func ( string) Option {
	return func( *Query) {
		.Builder.Datasource = &sdk.DatasourceRef{LegacyName: }
	}
}

// Request defines the query to be executed.
func ( string) Option {
	return func( *Query) {
		.Builder.Query = 
	}
}

// Sort defines the order in which the values will be sorted.
func ( SortOrder) Option {
	return func( *Query) {
		.Builder.Sort = int()
	}
}

// Refresh defines the interval in which the values will be refreshed.
func ( RefreshInterval) Option {
	return func( *Query) {
		 := int64()
		.Builder.Refresh = sdk.BoolInt{Flag: true, Value: &}
	}
}

// Regex defines a filter allowing to filter the values returned by the request/query.
func ( string) Option {
	return func( *Query) {
		.Builder.Regex = 
	}
}

// Label sets the label of the variable.
func ( string) Option {
	return func( *Query) {
		.Builder.Label = 
	}
}

// HideLabel ensures that this variable's label will not be displayed.
func () Option {
	return func( *Query) {
		.Builder.Hide = 1
	}
}

// Hide ensures that the variable will not be displayed.
func () Option {
	return func( *Query) {
		.Builder.Hide = 2
	}
}

// Multiple allows several values to be selected.
func () Option {
	return func( *Query) {
		.Builder.Multi = true
	}
}

// IncludeAll adds an option to allow all values to be selected.
func () Option {
	return func( *Query) {
		.Builder.IncludeAll = true
		.Builder.Options = append(.Builder.Options, sdk.Option{
			Text:  "All",
			Value: All,
		})
	}
}

// DefaultAll selects "All" values by default.
func () Option {
	return func( *Query) {
		.Builder.Current = sdk.Current{Text: &sdk.StringSliceString{Value: []string{"All"}, Valid: true}, Value: All}
	}
}

// AllValue defines a custom "all" value.
func ( string) Option {
	return func( *Query) {
		.Builder.AllValue = 
	}
}